<?
require_once("ericdingle/model/BaseProvider.php");

class PostLabelProvider extends BaseProvider {
	public static function getInstance() {
		return parent::getInstance(__CLASS__);
	}
	
	// CRUD
	
	public function create($post) {
		foreach ($post->getLabelIDs() as $labelID) {
			$this->dataInterface_->executeNonQuery(sprintf(
				"INSERT INTO PostLabel (PostID, LabelID) " .
				"VALUES (%d, %d)",
				$post->getPostID(),
				$labelID
			));
		}
	}
	
	public function read($entity = null, $orderBy = null, $limit = null) {
		die("PostLabelProvider.read() is not implemented.");
	}
	
	public function update($post) {
		$this->delete($post);
		$this->create($post);
	}
	
	public function delete($post) {
		$this->dataInterface_->executeNonQuery(sprintf(
			"DELETE FROM PostLabel " .
			"WHERE PostID = %d",
			$post->getPostID()
		));
	}
}
?>